package com.cyy.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.cyy.common.domain.Response;
import com.cyy.common.pojo.req.LoginReq;
import com.cyy.common.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "权限")
@Slf4j
@RestController
@RequestMapping("/system/authorize")
@RequiredArgsConstructor
public class AuthorizeController {

    private final UserService userService;

    @Operation(summary = "登录接口")
    @PostMapping("/login")
    public Response login(@RequestBody @Validated LoginReq req) {
        String tokenStr = userService.login(req);
        return Response.success().data(tokenStr);
    }

    @Operation(summary = "获取验证码")
    @GetMapping("/getCaptcha/{key}")
    public Response getCaptcha(@PathVariable("key") String key) {
        String verifyCode = userService.getVerifyCode(key);
        return Response.success().data(verifyCode);
    }


    @Operation(summary = "退出")
    @GetMapping("/logout")
    public Response login() {
        StpUtil.logout();
        return Response.success();
    }


//    @Operation(summary = "注册")
//    @PostMapping("/register")
//    public Response register(@RequestBody @Validated RegisterReq req) {
//        userService.register(req);
//        return Response.success().msg("注册成功");
//    }
}
